import { pushTemplatelist, deletedata } from "../../../server/api";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    pageNo: "1",
    pageSize: "10",
    list: [],
    active: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      list: [],
      pageNo: 1,
    });
    this.getdata();
  },
  //获取数据
  async getdata(res) {
    const params = {
      type: this.data.active,
      pageNo: res == undefined ? this.data.pageNo : res.pageNo,
      pageSize: res == undefined ? this.data.pageSize : res.pageSize,
    };
    const data = await pushTemplatelist(params);
    if (data.code == 200) {
      const val = data.result.records;
      this.setData({
        list: [...this.data.list, ...val],
      });
    }
  },
  async deleemsg(e) {
    console.log(e, "e");
    const { id } = e.currentTarget.dataset;
    const params = {
      id: id,
    };
    const res = await deletedata(params);
    if (res.code == 200) {
      this.setData({ list: [] });
      this.getdata();
    }
  },
  //滚动条事件
  getMore() {
    this.data.pageNo++;
    const params = {
      pageNo: this.data.pageNo,
      pageSize: this.data.pageSize,
    };
    this.getdata(params);
  },
  // tab事件切换
  onClick(e) {
    console.log(e, "e");
    if (e.detail.index == 0) {
      this.setData({ active: 0, list: [], pageNo: 1 });
      this.getdata();
    } else {
      this.setData({ active: 1, list: [], pageNo: 1 });
      this.getdata();
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
